using System;
using System.Collections.Generic;

public class myVector3D
{
    //The dx,dy,dz of this vector.
    public double dX, dY, dZ;

    public myVector3D()
    {
        dX = 0;
        dY = 0;
        dZ = 0;
    }


    public myVector3D(double dx, double dy, double dz)
    {
        dX = dx;
        dY = dy;
        dZ = dz;
    }

    //Returns the dot product of v1 and v2.
    public static myVector3D operator *(myVector3D v1, myVector3D v2)
    {
        myVector3D v = new myVector3D();
        v.dX = v1.dX * v2.dX;
        v.dY = v1.dY * v2.dY;
        v.dZ = v1.dZ * v2.dZ;
        return v;
    }

    //Returns the dot product of v1 and v2.
    public static myVector3D operator + (myVector3D v1, myVector3D v2)
    {
        myVector3D v = new myVector3D();
        v.dX = v1.dX + v2.dX;
        v.dY = v1.dY + v2.dY;
        v.dZ = v1.dZ + v2.dZ;
        return v;
    }

    //Returns the dot product of v1 and v2.
    public static myVector3D operator * (myVector3D v, double val)
    {
        v.dX *= val;
        v.dY *= val;
        v.dZ *= val;
        return v;
    }

    //Returns the dot product of v1 and v2.
    public static myVector3D operator *(double val, myVector3D v)
    {
        return v * val;
    }

    // Transforma two points in vector
    public static myVector3D MakeVector (myPoint3D p1, myPoint3D p2)
    {
        myPoint3D p = p2 - p1;
        return new myVector3D(p.X, p.Y, p.Z);
    }

    //Returns the lenth of the current vector.
    public double length()
    {
        return Math.Sqrt(dX*dX+dY*dY+dZ*dZ);
    }

    /// Retourne l'angle entre deux vecteur
    public static double GetAngle(myVector3D v1, myVector3D v2)
    {
        myVector3D doProduct = new myVector3D();
        double dot = myUtil.computeDotproduct(v1,v2);

        double radian = Math.Acos(dot / (v1.length() * v2.length()));
        double degree = 180 * radian / Math.PI;
        return degree;
    }

    //Normalizes the current vector to have unit length.
    public void normalize()
    {
        myVector3D aVector = this / length();
        dX = aVector.dX;
        dY = aVector.dY;
        dZ = aVector.dZ;
    }

    public static myVector3D operator / (myVector3D v, double val)
    {
        v.dX /= val;
        v.dY /= val;
        v.dZ /= val;
        return v;
    }

    public myVector3D GetClone()
    {
        return new myVector3D(dX, dY, dZ);
    }

    /// produit vectoriel
    public static myVector3D operator ^(myVector3D a, myVector3D b) 
    {
        myVector3D t = new myVector3D();
        t.dX = a.dY * b.dZ - a.dZ * b.dY;
        t.dY = a.dZ * b.dX - a.dX * b.dZ;
        t.dZ = a.dX * b.dY - a.dY * b.dX;
        return t;
    }

    /// produit scalaire
    /*
    public static double operator *(myVector3D a, myVector3D b)
    {
        return a.dX * b.dX + a.dY * b.dY + a.dZ * b.dZ;
    }
     * */
}
